<!-- 详细记录信息 -->
<template>
  <div >
    <van-form @submit="onSubmit">
      <van-field v-model="pimForm.name" name="姓名" label="姓名：" placeholder="姓名" />
      <!-- <van-field name="radio" label="性别：">
        <template #input>
          <van-radio-group v-model="pimForm.sex" direction="horizontal">
            <van-radio name="1">男</van-radio>
            <van-radio name="2">女</van-radio>
          </van-radio-group>
        </template>
      </van-field> -->
      <!-- <van-field
        readonly
        clickable
        name="picker"
        :value="value"
        label="职业部门："
        placeholder="请选择职业部门"
        @click="showPicker = true"
      />
      <van-popup v-model="showPicker" position="bottom">
        <van-picker
          show-toolbar
          :columns="columns"
          @confirm="onConfirm"
          @cancel="showPicker = false"
        />
      </van-popup> -->
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit" >保存</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
export default {
  name: "PimRecord",
  data() {
    return {
      showPicker: false,
      columns: [], //职业部门
      department_id: Number,
      value: "",
      avatar: "", //頭像
      pimForm: {
        name: "",
        sex: ""
      },
    };
  },
  methods: {
    // onConfirm(value, index) {
    //   this.value = value;
    //   let department_id = this.departments[index].id
    //   this.showPicker = false;
    //   console.log(`当前值：${value}, 当前索引：${index}` ,department_id);
    // },
    //获取部门数据
    // dataInit() {
    //   this.$http({
    //     method: "post",
    //     url: "index/common/getDepartment"
    //   }).then(res => {
    //     // console.log(res);
    //     if (res.data.State.Code == 200) {
    //        this.departments = res.data.data;
    //       for (const item of res.data.data) {
    //         let columns = `${item.cate_title}`;
    //         this.columns.push(columns);
    //         // console.log(this.columns);
    //       }
    //     }
    //   });
    // },
    //获取个人信息
    async receiveInfor() {
      // console.log(131)
      let user_id = window.localStorage.getItem('user_id')
      let status = "user";
      try {
        await this.$http({
          method: "post",
          url: "index/web/doSelfInfos",
          headers: { "X-Requested-With": "XMLHttpRequest" }, // 必须加这个请求头 否则报错：500
          data: {
            user_id,
            status
          }
        })
          .then(res => {
            console.log(res)
            const myInfor = res.data;
            if (myInfor.State.Code == 200) {
              this.pimForm.name = myInfor.data.name;
              this.$store.commit("HeadPortrait", myInfor.data.avatar);
              this.$store.commit("UserName", myInfor.data.name);
              // this.value = myInfor.data.department;
              // this.department_id = myInfor.data.department_id;
              // console.log(res);
              console.log(this.department_id);
              // if (myInfor.data.sex == "男") {
              //   this.pimForm.sex = "1";
              // } else {
              //   this.pimForm.sex = "2";
              // }
              // console.log(myInfor.data.sex);
            // } else if (res.data.State.Code == "2027") {
            
              //  this.$Notify({ type: "danger", message: "未关联部门" });
            }
          })
          .catch(err => {
            console.log(err);
          });
      } catch (error) {
        console.log("获取个人资料接口出现了问题...");
      }
    },
    //保存信息
    onSubmit() {
      console.log("保存信息");
      let user_id = window.localStorage.getItem('user_id')
      let status = "userUpdate";
      const param = {};
      let avatar = this.$store.state.HeadPortrait; // 老头像
      param.name = this.pimForm.name; // 姓名
      // param.sex = this.pimForm.sex; // 性别
      // param.department_id = this.department_id; // 职业部门id
      // console.log(this.department_id)
      // console.log(user_id, avatar, status, param);
      this.$http({
        method: "post",
        url: "index/web/doSelfInfos",
        data: {
          user_id,
          status,
          param
        }
      })
        .then(res => {
          console.log(res);
          if (res.data.State.Code == 200) {
             this.$Notify({ type: "success", message: "修改资料申请已经提交...进行下一步" });
            this.$router.push({ path: "/pim/pimrecord2" });
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  },
  mounted() {
    this.receiveInfor();
    // this.dataInit();
  }
};
</script>
<style lang='scss' scoped>
</style>